package com.actionpals.graphics
{
	import flash.display.GradientType;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.geom.Matrix;
	
	public class Gradient extends EventDispatcher
	{	
		protected var _type:String;
		protected var _colors:Array;
		protected var _alphas:Array;
		protected var _ratios:Array;
		protected var _matrix:Matrix;
		protected var _spreadMethod:String;
		protected var _interpolationMethod:String;
		protected var _focalPointRatio:Number;
		
		public function Gradient
		(
			type:String = GradientType.LINEAR,
			colors:Array = null,
			alphas:Array = null,
			ratios:Array = null,
			matrix:Matrix = null,
			spreadMethod:String = "pad",
			interpolationMethod:String = "rgb",
			focalPointRatio:Number = 0
		)
		{
			_type = type;
			_colors = colors;
			_alphas = alphas;
			_ratios = ratios;
			_matrix = matrix;
			_spreadMethod = spreadMethod;
			_interpolationMethod = interpolationMethod;
			_focalPointRatio = focalPointRatio;
		}
		
		/**
		 * A value from the GradientType class that specifies which gradient type to use: 
		 * GradientType.LINEAR or GradientType.RADIAL.
		 */
		public function get type():String
		{
			return _type
		}

		/**
		 * @private
		 */
		public function set type( value:String ):void
		{
			_type = value;
			dispatchChange()
		}
		
		/**
		 * An array of RGB hexadecimal color values to be used in the gradient; for example, 
		 * red is 0xFF0000, blue is 0x0000FF, and so on. You can specify up to 15 colors. 
		 * For each color, be sure you specify a corresponding value in the alphas and ratios parameters. 
		 */
		public function get colors():Array
		{
			return _colors
		}

		/**
		 * @private
		 */
		public function set colors( value:Array ):void
		{
			_colors = value;
			dispatchChange()
		}
		
		/**
		 * An array of alpha values for the corresponding colors in the colors array; 
		 * valid values are 0 to 1. If the value is less than 0, the default is 0. 
		 * If the value is greater than 1, the default is 1.
		 */
		public function get alphas():Array
		{
			return _alphas
		}

		/**
		 * @private
		 */
		public function set alphas( value:Array ):void
		{
			_alphas = value;
			dispatchChange()
		}
		
		/**
		 * An array of color distribution ratios; valid values are 0 to 255. This value defines the 
		 * percentage of the width where the color is sampled at 100%. The value 0 represents the 
		 * left-hand position in the gradient box, and 255 represents the right-hand position in the gradient box.
		 */
		public function get ratios():Array
		{
			return _ratios
		}

		/**
		 * @private
		 */
		public function set ratios( value:Array ):void
		{
			_ratios = value;
			dispatchChange()
		}
		
		/**
		 * A transformation matrix as defined by the flash.geom.Matrix class. 
		 * The flash.geom.Matrix class includes a createGradientBox() method, which lets 
		 * you conveniently set up the matrix for use with the beginGradientFill() method.
		 */
		public function get matrix():Matrix
		{
			return _matrix
		}

		/**
		 * @private
		 */
		public function set matrix( value:Matrix ):void
		{
			_matrix = value;
			dispatchChange()
		}
		
		/**
		 * A value from the SpreadMethod class that specifies which spread method to use, either: 
		 * SpreadMethod.PAD, SpreadMethod.REFLECT, or SpreadMethod.REPEAT.
		 */
		public function get spreadMethod():String
		{
			return _spreadMethod
		}

		/**
		 * @private
		 */
		public function set spreadMethod( value:String ):void
		{
			_spreadMethod = value;
			dispatchChange()
		}
		
		/**
		 * A value from the InterpolationMethod class that specifies which value to use: 
		 * InterpolationMethod.linearRGB or InterpolationMethod.RGB
		 */
		public function get interpolationMethod():String
		{
			return _interpolationMethod
		}

		/**
		 * @private
		 */
		public function set interpolationMethod( value:String ):void
		{
			_interpolationMethod = value;
			dispatchChange()
		}
		
		/**
		 * A number that controls the location of the focal point of the gradient. 
		 * 0 means that the focal point is in the center. 1 means that the focal point is at one 
		 * border of the gradient circle. -1 means that the focal point is at the other border of 
		 * the gradient circle. A value less than -1 or greater than 1 is rounded to -1 or 1.
		 */
		public function get focalPointRatio():Number
		{
			return _focalPointRatio
		}

		/**
		 * @private
		 */
		public function set focalPointRatio( value:Number ):void
		{
			_focalPointRatio = value;
			dispatchChange()
		}
		
		/**
		 * @private
		 */		
		protected function dispatchChange():void
		{
			if( hasEventListener( Event.CHANGE ) ) dispatchEvent( new Event( Event.CHANGE ) );
		}
	}
}